<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Default_Model_Loaidaily extends ZF_DB{
    protected $_table_name = "loaidaily" ;
    
    protected $_maloaidaily;
    protected $_phantramhoahong;
    protected $_tenloaidaily;
    protected $_phantrambonus;
    
    public function getMaLoaiDaiLy(){
        return $this->_maloaidaily;
    }
    public function setMaLoaiDaiLy($maloaidaily){
        $this->_maloaidaily = $maloaidaily;
    }
    public function getPhanTramHoaHong(){
        return $this->_phantramhoahong;
    }
    public function setPhanTramHoaHong($phantramhoahong){
        $this->_phantramhoahong = $phantramhoahong;
    }
    public function getTenLoaiDaiLy(){
        return $this->_tenloaidaily;
    }
    
    public function setTenLoaiDaiLy($tenloaidaily){
       $this->_tenloaidaily = $tenloaidaily;
    }
    public function getPhanTramBonus(){
        return $this->_phantrambonus;
    }
    public function setPhanTramBonus($phantrambonus){
        $this->_phantrambonus = $phantrambonus;
    }
    
    public function insert($name,$name_en,
            $description = "",$description_en = "",
            $phone ="",$city = 0,$address ="",
            $images ="",
            $rate = 0,$counter = 0,$active=1){
        
        if($name){             
                $data =  array(
                    'name' =>$name,
                    'name_en'=>$name_en,
                    'description' =>$description,
                    'description_en'=>$description_en,
                    'images'=>$images,
                    'phone'=>$phone,
                    'address'=>$address,
                    'city' =>$city,
                    'active'=>$active);
            return         $this->db->insert($this->_table_name,$data);
	
	}
        return -1;
	
    }
   
    public function update($madaily, $data){
        $where  = "MaDaiLy = " . $madaily;
	return $this->db->update(
                $this->_table_name,
                $data,$where);
    }
   
    public function getById($maloaidaily){
        if($maloaidaily)
	{
		$select = $this->db->select()
			->from(array("p"=>$this->_table_name))
                        ->where("p.MaLoaiDaiLy = ?",$maloaidaily );
		
		$data = $this->db->fetchRow($select);
		if($data){
			$this->_maloaidaily = $data['MaLoaiDaiLy'];
			$this->_phantramhoahong = $data['PhanTramHoaHong'];
			$this->_tenloaidaily = $data['TenLoaiDaiLy'];
                        $this->_phantrambonus = $data['PhanTramBonus'];
		}
                return $data;
	}
	return -1;
    }
   
    public function listAll(){
        $select = $this->db->select()
                ->from($this->_table_name);
        $data = $this->db->fetchAll($select);
	return $data;
    }
    public function delete(){
            $this->getById($this->_id);
            $this->_active = 0;
            return $this->update();
    }
}
?>
